package com.example.secondhandsysapi.Controller;

import com.example.secondhandsysapi.Entity.ActionLogInfo;
import com.example.secondhandsysapi.Service.ActionLogInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@CrossOrigin
@RestController
@RequestMapping(value="act")

public class ActionLogInfoController {
    @Autowired
    private ActionLogInfoService actionLogInfoService;

    // http://localhost:8080/act/del/
    @GetMapping("del/{act_id}")
    private Integer delActionInfo(@PathVariable Integer act_id) {
        return actionLogInfoService.deleteByID(act_id);
    }
    // http://localhost:8080/act/querythree
    @GetMapping("/querythree")
    public List<ActionLogInfo> queryActionLogInfo(@RequestParam(required = false) Integer user_id,@RequestParam(required = false) String act_outcome,@RequestParam(required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date act_time) {
        if(user_id!=null&&act_outcome!=null&&act_time!=null) {
            return actionLogInfoService.getAllActionLogInfoUserIdOutcomeTime(user_id,act_outcome,act_time);
        } else if (act_outcome!=null&&user_id==null&&act_time==null) {
            return actionLogInfoService.getAllActionLogInfoOutcome(act_outcome);
        } else if (act_outcome!=null&&user_id!=null&&act_time==null) {
            return actionLogInfoService.getAllActionLogInfoOutcomeId(act_outcome,user_id);
        } else if (act_outcome!=null&&user_id==null&&act_time!=null) {
            return  actionLogInfoService.getAllActionLogInfoOutcomeTime(act_outcome,act_time);
        } else if (user_id!=null&&act_outcome==null&&act_time==null) {
            return  actionLogInfoService.getAllActionLogInfoUserId(user_id);
        } else if (act_time!=null&&user_id==null&&act_outcome==null) {
            return actionLogInfoService.getAllActionLogInfoTime(act_time);
        }else if (act_time!=null&&user_id!=null&&act_outcome==null) {
            return actionLogInfoService.getAllActionLogInfoUserIdTime(user_id,act_time);
        }else {
            return  actionLogInfoService.getAllActionLogInfo();
        }

    }

}